const { Router } = require("express");
const md5 = require("md5");
const Hotel = require("../model/Hotel");
const router = new Router();

// 查询某个商家的故事

// localhost:2233/api/hotels/admin
router.get("/admin", async (req, res) => {
  let { page, count } = req.query;
  //  console.log(page, count);
  const rees = await Hotel.find().populate("owenerId")
    .skip(count * (page - 1)) /*跳过多少条开始查询*/
    .limit(count); /*查询多少条数据*/

  //  console.log(rees);
  res.send(rees);
});

// 查询所有商家故事
// localhost:2233/api/hotels/cxhotels
router.get("/cxhotels", async (req, res) => {
  const data = await Hotel.find()

  //  console.log(rees);
  res.send(data);
});

//请求酒店的详情数据 
router.get("/detail", async (req, res) => {

  let { id } = req.query;
  // console.log(id , 123);
  const list = await Hotel.find({ _id: id }).populate("owenerId");
  
  res.status(200).json({list});
});


// id 查找酒店主人
router.get("/hotelowner", async (req, res) => {
  let { id } = req.query;
  // res.send('444')
  // console.log(id);
  const list = await Hotel.find({ _id: id }).populate("owenerId");
  // console.log(list);

  res.send(list)
});

module.exports = router
